package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNav;
import com.ruoyi.system.service.ISysNavService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统导航Controller
 * 
 * @author ruoyi
 * @date 2023-03-26
 */
@RestController
@RequestMapping("/system/nav")
public class SysNavController extends BaseController
{
    @Autowired
    private ISysNavService sysNavService;

    /**
     * 查询系统导航列表
     */
    @PreAuthorize("@ss.hasPermi('system:nav:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNav sysNav)
    {
        startPage();
        List<SysNav> list = sysNavService.selectSysNavList(sysNav);
        return getDataTable(list);
    }

    /**
     * 导出系统导航列表
     */
    @PreAuthorize("@ss.hasPermi('system:nav:export')")
    @Log(title = "系统导航", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysNav sysNav)
    {
        List<SysNav> list = sysNavService.selectSysNavList(sysNav);
        ExcelUtil<SysNav> util = new ExcelUtil<SysNav>(SysNav.class);
        util.exportExcel(response, list, "系统导航数据");
    }

    /**
     * 获取系统导航详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:nav:query')")
    @GetMapping(value = "/{navId}")
    public AjaxResult getInfo(@PathVariable("navId") Long navId)
    {
        return success(sysNavService.selectSysNavByNavId(navId));
    }

    /**
     * 新增系统导航
     */
    @PreAuthorize("@ss.hasPermi('system:nav:add')")
    @Log(title = "系统导航", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNav sysNav)
    {
        return toAjax(sysNavService.insertSysNav(sysNav));
    }

    /**
     * 修改系统导航
     */
    @PreAuthorize("@ss.hasPermi('system:nav:edit')")
    @Log(title = "系统导航", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNav sysNav)
    {
        return toAjax(sysNavService.updateSysNav(sysNav));
    }

    /**
     * 删除系统导航
     */
    @PreAuthorize("@ss.hasPermi('system:nav:remove')")
    @Log(title = "系统导航", businessType = BusinessType.DELETE)
	@DeleteMapping("/{navIds}")
    public AjaxResult remove(@PathVariable Long[] navIds)
    {
        return toAjax(sysNavService.deleteSysNavByNavIds(navIds));
    }
}
